package com.shixun.milktea.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.shixun.milktea.entity.Mt;
import com.shixun.milktea.entity.Sort;
import com.shixun.milktea.entity.Swiper;
import com.shixun.milktea.mapper.SwiperMapper;
import com.shixun.milktea.service.SwiperService;
import com.shixun.milktea.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zrs
 * @since 2022-06-12
 */
@RestController
@RequestMapping("/swiper")
@Api(tags = "小程序轮播图相关接口")
public class SwiperController {
    @Autowired
    SwiperMapper swiperMapper;
    @Autowired
    SwiperService swiperService;


    @GetMapping("/findAllSwiper")
    @ApiOperation(value = "查询所有轮播图")
    public ResultVO queryAllSwiper() throws Exception {
        QueryWrapper<Swiper> qw=new QueryWrapper<>();
        List<Swiper> mtList = swiperMapper.selectList(qw);

        return new ResultVO(mtList);
    }


    @PostMapping("/addSwiper")
    @ApiOperation(value = "添加轮播图信息")
    public ResultVO addSwiper(@RequestBody Swiper swiper) throws Exception {

        int insert = swiperMapper.insert(swiper);

        return new ResultVO(insert);
    }

    @PutMapping("/updateSwiper")
    @ApiOperation(value = "修改轮播图信息")
    public ResultVO updateSwiper(@RequestBody Swiper swiper) throws Exception {

        int i = swiperMapper.updateById(swiper);

        return new ResultVO(i);
    }


    @PutMapping("/updateSwiperSatusUp")
    @ApiOperation(value = "轮播图上架")
    public ResultVO updateSwiperStatusUp(@RequestParam("swiperId") int swiperId) throws Exception {
        int i = swiperService.updateSwiperStatusUp(swiperId);
        return new ResultVO(i);
    }

    @PutMapping("/updateSwiperSatusDown")
    @ApiOperation(value = "轮播图下架")
    public ResultVO updateSwiperStatusDown(@RequestParam("swiperId") int swiperId) throws Exception {
        int i = swiperService.updateSwiperStatusDown(swiperId);
        return new ResultVO(i);
    }


    @DeleteMapping("/deleteSwiperById")
    @ApiOperation(value = "根据id删除轮播图信息")
    public ResultVO deleteSwiperById(@RequestParam("swiperId") int swiperId) throws Exception {
        int i = swiperMapper.deleteById(swiperId);
        return new ResultVO(i);
    }




}
